<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="shortcut icon" href="../public/images/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../public/stylesheets/reset.css" />
    <link rel="stylesheet" type="text/css" href="../public/stylesheets/register.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../public/images/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">使用手机号登陆</li>
                <li></li>
            </ul>
            <form action="javascript:;" id="form">
                <input style="margin-top: 0;" type="text" name="username" id="user" placeholder="请输入您的手机号">
                <input type="password" name="password" id="pass" placeholder="请输入密码">
                <input type="password" placeholder="请再次输入密码" id="pass2" name="password2">
                <p id="msg"></p>
                <button class="loginbtn">注册</button>
            </form>
            <p>
                <input type="checkbox" class="xuanze" />
                <span><a href="javascript:;">我同意 《用户使用协议》</a></span>
                <span>
                    已有账号
                    <a href="javascript:;">去登陆</a>
                </span>
            </p>
        </div>
    </div>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./myajax.js"></script>
    <script>
        $('.loginbtn').click(async function () {
            let [err, res] = await fn({
                type: 'post',
                url: 'http://localhost:3000/register',
                data: {
                    username: $('#user').val(),
                    password: $('#pass').val(),
                    password2: $('#pass2').val()
                }
            })
            if (err) {
                $('#msg').html('请稍后重试');
                return;
            }
            if (res.code == 200) {
                alert(res.msg);
                location.href = './login.html';
            }
            else {
                $('#msg').html(res.msg);
            }
        })
    </script>
</body>

</html>